<?php
require_once "config.php";

$id = $_GET['id'];
$username = $_POST['username'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];
if(!empty($username)&&!empty($password1)){
    if($password1 == $password2){
        $sql = "update admin set name='{$username}',password='{$password1}' where id = $id";
        $rst = mysqli_query($con,$sql);
        $id = mysqli_affected_rows($con);
        if($id){
            echo "<script>alert('编辑成功!');window.location.href='main_list.php';</script>";
        }else{
            echo "<script>alert('编辑失败,请重新输入');window.location.href='edit.php?id=$id';</script>";
        }
    }else{
        echo "<script>alert('两次密码不一致,请重新输入');window.location.href='edit.php?id=$id';</script>";
    }
}else{
    echo "<script>alert('用户名或密码为空,请重新输入');window.location.href='edit.php?id=$id';</script>";
}